package cqupt.spark_log.main;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;

import cqupt.spark_log.contrant.Contant;
import cqupt.spark_log.entity.StrategyTable;
import cqupt.spark_log.fileio.FileFilterMan;
import cqupt.spark_log.info.ExcelInfoByStage;
import cqupt.spark_log.utils.Utils;
/**
 * 更加细致，统计每个阶段的能耗和时间，并生成excel
 * @author TomWang
 *
 */
public class ExcelMainByStage {
	public static void main(String[] args) throws IOException {
		ExcelInfoByStage excelInfoByStage = new ExcelInfoByStage();
		String experimentPath = Utils.getExperimentPath(Contant.BASE_PATH);
		File file = new File(experimentPath);
		FileFilter filter = new FileFilterMan();
		if (file.exists()) {
			File[] files = file.listFiles(filter);
			int count = 0;
			for (File tmpFile : files) {
				count ++;
				String name = tmpFile.getName();
				String[] names = name.split("-");
				String algorithm = names[0];
				String parallel = names[1];
				String index = names[2];
				File[] childFiles = tmpFile.listFiles();
				int count1 = 0;
				for (File tmpChildFile : childFiles) {
					if (tmpChildFile.isDirectory()) {
						count1++;
						String workLoad = tmpChildFile.getName();
						System.out.println(">>>"+name+"."+workLoad+">>>"+count+"."+count1);
						/*从新生成策略表*/
//						Contant.APP_NAME = workLoad;
//						Contant.BASE_PATH = tmpChildFile.getCanonicalPath();
//						Main.main(args);
						String path = tmpChildFile.getCanonicalPath() + "\\" + workLoad;
						StrategyTable strategyTable = new StrategyTable(path);
						String[] stageList = strategyTable.getStageList();
						int count2 = 0;
						for (int i=0;i<stageList.length;i++) {
							count2++;
							System.out.println(">>>"+name+"."+workLoad+"."+stageList[i]+">>>"+count+"."+count1+"."+count2);
							excelInfoByStage.saveInfo(algorithm,parallel,index,workLoad,name,stageList[i]);
						}
					}
				}
				System.out.println(">>>"+name+">>>"+count);
			}
			excelInfoByStage.writeAndclose();
		}
	}
}
